package it.blueocean.acanto.taglibrary.jsp.taglib.tags;

import it.blueocean.acanto.taglibrary.jsp.taglib.tags.exceptions.ComponentStateBeanPropertyNotFoundException;

import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public abstract class AbstractComponentStateBean implements Serializable
{
	private String componentId_;

	private static Class[] SETTER_PARAM_ARRAY = { String.class };

	private static Class[] SETTER_PARAM = { String.class };

	public String getId()
	{
		return this.componentId_;
	}

	public void setId(String paramString)
	{
		this.componentId_ = paramString;
	}

	public Object getProperty(String paramString) throws ComponentStateBeanPropertyNotFoundException
	{
		String str = "get" + Character.toUpperCase(paramString.charAt(0)) + paramString.substring(1);
		try
		{
			Method localMethod = super.getClass().getMethod(str, null);
			Object localObject = localMethod.invoke(this, null);
			return ((localObject != null) ? localObject.toString() : null);
		}
		catch (Exception localException)
		{
			throw new ComponentStateBeanPropertyNotFoundException(getId(), paramString, localException);
		}
	}

	public void setProperty(String paramString, String[] paramArrayOfString)
			throws ComponentStateBeanPropertyNotFoundException, InvocationTargetException
	{
		String str = "set" + Character.toUpperCase(paramString.charAt(0)) + paramString.substring(1);
		Method localMethod;
		try
		{
			localMethod = super.getClass().getMethod(str, SETTER_PARAM_ARRAY);
			Object[] arrayOfObject1 = { paramArrayOfString };
			localMethod.invoke(this, arrayOfObject1);
			System.out.println("setterParams array");
		}
		catch (Exception localException)
		{
			try
			{
				localMethod = super.getClass().getMethod(str, SETTER_PARAM);
				Object[] arrayOfObject2 = { paramArrayOfString[0] };
				localMethod.invoke(this, arrayOfObject2);
				System.out.println("setterParams [0]");
			}
			catch (SecurityException localSecurityException)
			{
				throw new ComponentStateBeanPropertyNotFoundException(getId(), paramString, localSecurityException);
			}
			catch (NoSuchMethodException localNoSuchMethodException)
			{
				throw new ComponentStateBeanPropertyNotFoundException(getId(), paramString, localNoSuchMethodException);
			}
			catch (IllegalArgumentException localIllegalArgumentException)
			{
				throw new ComponentStateBeanPropertyNotFoundException(getId(), paramString,
						localIllegalArgumentException);
			}
			catch (IllegalAccessException localIllegalAccessException)
			{
				throw new ComponentStateBeanPropertyNotFoundException(getId(), paramString, localIllegalAccessException);
			}
		}
	}
}
